package com.ruoyi.web.controller.module.union;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.utils.MyUtils;
import com.ruoyi.customer.domain.CustomerUser;
import com.ruoyi.customer.service.ICustomerUserService;
import com.ruoyi.market.domain.*;
import com.ruoyi.market.service.*;
import com.ruoyi.order.domain.OrderGift;
import com.ruoyi.order.domain.OrderGoods;
import com.ruoyi.order.service.IOrderGiftService;
import com.ruoyi.order.service.IOrderGoodsService;
import com.ruoyi.system.service.ISysDictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 服务项目信息
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/union/unionStatic")
public class UnionStaticController extends BaseController
{
    @Autowired
    private ICustomerUserService userService;

    @Autowired
    private IOrderGoodsService orderGoodsService;

    @Autowired
    private IOrderGiftService orderGiftService;

    @PostMapping("/getUnionStaticList")
    public AjaxResult getDictList(HttpServletRequest request, @RequestBody Map<String, Object> params)
    {
        AjaxResult ajax = AjaxResult.success();
        String shopId = "";
        if(params.get("shopId") != null && !params.get("shopId").equals("")){
            shopId = params.get("shopId").toString();
        }
        if (request.getHeader("ShopId") != null && !request.getHeader("ShopId").equals("")) {
            shopId = request.getHeader("ShopId");
        }
        CustomerUser user = new CustomerUser();
        OrderGoods orderGoods = new OrderGoods();
        OrderGift orderGift = new OrderGift();
        user.setShopId(shopId);
        user.setParams(params);
        orderGoods.setShopId(shopId);
        orderGoods.setParams(params);
        orderGift.setShopId(shopId);
        orderGift.setParams(params);
        int customerUserCountTotal = userService.selectUserCountTotal(user);
        List<Map<String, Object>> customerUserCountDaily = userService.selectUserCountDaily(user);
        ajax.put("customerUserCountTotal", customerUserCountTotal);
        ajax.put("customerUserCountDaily", customerUserCountDaily);

        int orderGoodsCountTotal = orderGoodsService.selectOrderGoodsCountTotal(orderGoods);
        List<Map<String, Object>> orderGoodsCountDaily = orderGoodsService.selectOrderGoodsCountDaily(orderGoods);
        ajax.put("orderGoodsCountTotal", orderGoodsCountTotal);
        ajax.put("orderGoodsCountDaily", orderGoodsCountDaily);

        BigDecimal orderGoodsAmountTotal = orderGoodsService.selectOrderGoodsAmountTotal(orderGoods);
        List<Map<String, Object>> orderGoodsAmountDaily = orderGoodsService.selectOrderGoodsAmountDaily(orderGoods);
        ajax.put("orderGoodsAmountTotal", orderGoodsAmountTotal);
        ajax.put("orderGoodsAmountDaily", orderGoodsAmountDaily);

        int orderGiftCountTotal = orderGiftService.selectOrderGiftCountTotal(orderGift);
        List<Map<String, Object>> orderGiftCountDaily = orderGiftService.selectOrderGiftCountDaily(orderGift);
        ajax.put("orderGiftCountTotal", orderGiftCountTotal);
        ajax.put("orderGiftCountDaily", orderGiftCountDaily);

        BigDecimal orderGiftAmountTotal = orderGiftService.selectOrderGiftAmountTotal(orderGift);
        List<Map<String, Object>> orderGiftAmountDaily = orderGiftService.selectOrderGiftAmountDaily(orderGift);
        ajax.put("orderGiftAmountTotal", orderGiftAmountTotal);
        ajax.put("orderGiftAmountDaily", orderGiftAmountDaily);
        return ajax;
    }

}
